/*
 * Copyright
 */
package org.springframework.cloud.netflix.eureka.server;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;

import static org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties.PREFIX;

/**
 * 实例注册配置
 * <p>
 * eureka.instance.registry.**
 *
 * @author ztkool
 * @since 1.0.0
 */
@ConfigurationProperties(PREFIX)
public class InstanceRegistryProperties {

    public static final String PREFIX = "eureka.instance.registry";

    /**
     * 发送续订的预期客户端数
     * <p>
     * for backwards compatibility 向后兼容
     * <p>
     * Default number of expected client, defaults to 1. Setting
     * expectedNumberOfClientsSendingRenews to non-zero to ensure that even an isolated
     * server can adjust its eviction policy to the number of registrations (when it's
     * zero, even a successful registration won't reset the rate threshold in
     * InstanceRegistry.register()).
     */
    @Value("${eureka.server.expectedNumberOfRenewsPerMin:1}")
    private int expectedNumberOfClientsSendingRenews = 1;

    /**
     * 默认开放进行流量统计
     * <p>
     * 用于确定何时取消租约的值，对于独立租约，默认值为1。对于对等复制的eurekas，应将设置为0
     * <p>
     * for backwards compatibility 向后兼容
     * <p>
     * Value used in determining when leases are cancelled, default to 1 for standalone.
     * Should be set to 0 for peer replicated eurekas
     */
    @Value("${eureka.server.defaultOpenForTrafficCount:1}")
    private int defaultOpenForTrafficCount = 1;

    public int getExpectedNumberOfClientsSendingRenews() {
        return expectedNumberOfClientsSendingRenews;
    }

    public void setExpectedNumberOfClientsSendingRenews(
            int expectedNumberOfClientsSendingRenews) {
        this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews;
    }

    @DeprecatedConfigurationProperty(replacement = PREFIX
            + ".expected-number-of-clients-sending-renews")
    @Deprecated
    public int getExpectedNumberOfRenewsPerMin() {
        return getExpectedNumberOfClientsSendingRenews();
    }

    @Deprecated
    public void setExpectedNumberOfRenewsPerMin(int expectedNumberOfRenewsPerMin) {
        setExpectedNumberOfClientsSendingRenews(expectedNumberOfRenewsPerMin);
    }

    public int getDefaultOpenForTrafficCount() {
        return defaultOpenForTrafficCount;
    }

    public void setDefaultOpenForTrafficCount(int defaultOpenForTrafficCount) {
        this.defaultOpenForTrafficCount = defaultOpenForTrafficCount;
    }

}
